package reverselist

type ListNode struct{
	Val int
	Next *ListNode
}

// 反转
func reverseList(head *ListNode) *ListNode {
	// 头插法
	if head == nil {
		return head
	}
	newHead := &ListNode{}
	// lastOfNew := head
	for head != nil {
		// 把head 插到newHead之后
		next := head.Next

		head.Next = newHead.Next
		newHead.Next = head

		head = next
	}
	return newHead.Next
}